package com.example.demo.controller;

import com.example.demo.bean.pmsBaseCatalog.PmsBaseCatalog1;
import com.example.demo.bean.pmsBaseCatalog.PmsBaseCatalog2;
import com.example.demo.service.PmsBaseCatalogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@CrossOrigin
@RequestMapping("iteam")
@Api("一级分类controller")
@Controller
public class PmsBaseCatalogController {
    @Autowired
    PmsBaseCatalogService pmsBaseCatalogService;

    @ApiOperation(value = "获取一级分类列表",notes = "获取一级分类列表")
    @GetMapping("/catalog1/all")
    @ResponseBody
    public List<PmsBaseCatalog1> getAll(){
       return pmsBaseCatalogService.getList();
    }

    @ApiOperation(value = "获取二级分类列表",notes = "根据一级分类id获取二级分类,三级分类联合列表")
    @GetMapping("/catalog1/{id}")
    @ResponseBody
    public List<PmsBaseCatalog2> getCatalog2(@PathVariable String id) {
        List<PmsBaseCatalog2> pmsBaseCatalog2s = new ArrayList<>();
        pmsBaseCatalog2s = pmsBaseCatalogService.getCatalog2(id);
        for (PmsBaseCatalog2 catalog2: pmsBaseCatalog2s
             ) {
            if(catalog2!=null)
            catalog2.setCatalog3s(pmsBaseCatalogService.getCataLog3(catalog2.getId()));
        }
        return pmsBaseCatalog2s;
    }
}
